﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QAAdmin.BusinessObject;

namespace QAAdmin.UI
{
    public partial class frmLogin : BaseFormWithHeader
    {
        public frmLogin()
        {
            try
            {
                InitializeComponent();
                txtUsername.Select();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnMasuk_Click(object sender, EventArgs e)
        {
            try
            {                
                this.Cursor = Cursors.WaitCursor;

                string username = txtUsername.Text;
                string password = txtPassword.Text;
                if (QAController.Login(username, password))
                {
                    QAController.Username = username;                    
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    QAController.UbahStatusLoginPetugas(1);
                }
                else
                {
                    string msg = "Username atau password salah. Hanya anggota group administrator/supervisor yang diizinkan login";
                    MessageBox.Show(msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

    }
}
